/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.hogent.designpatterns.billenkar.commands;

import be.hogent.designpatterns.billenkar.Billenkar;
import java.util.Scanner;

/**
 *
 * @author Jeroen
 */
public class VeranderStatusCommand implements Command {
    private Billenkar kar;
    private Scanner in = new Scanner(System.in);
    private Command[] statusCommands;

    public VeranderStatusCommand(Billenkar kar) {
        this.kar = kar;
        statusCommands = new Command[3];
        statusCommands[0] = new VerhuurdCommand();
        statusCommands[1] = new InReparatieCommand();
        statusCommands[2] = new InWinkelCommand();
    }

    public void execute()
    {
        int keuze = maakStatusMenu();
        while(keuze == -1) {
            System.out.println("ONGELDIGE KEUZE!");
            keuze = maakStatusMenu();
        }
        statusCommands[keuze-1].execute();
    }

    private int maakStatusMenu() {
      System.out.println("****************************************************");
      System.out.println("                   KIES STATUS");
      System.out.println("****************************************************");
      System.out.println("");
      System.out.println("");
      System.out.println("1. Verhuurd");
      System.out.println("2. In reparatie");
      System.out.println("3. In winkel");
      System.out.println("Maak uw keuze: ");
      String inv = in.nextLine();

      int keuze;
      try {
         keuze = Integer.parseInt(inv);
         if(keuze<1 || keuze>3)
             throw new NumberFormatException();
      } catch (NumberFormatException nfe) {
         keuze = -1;
      }
      return keuze;
   }


   public class InWinkelCommand implements Command{

      public void execute() {
         kar.zetInWinkel();
      }

   }
   public class InReparatieCommand implements Command{

      public void execute() {
         kar.zetInReparatie();
      }

   }
   public class VerhuurdCommand implements Command{

      public void execute() {
         kar.verhuur();
      }

   }

}
